/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_CYCLONE_PARTICIPANT_MONITOR_HPP_
#define _DAL_CYCLONE_PARTICIPANT_MONITOR_HPP_

#include <iostream>
#include <vector>
#include <mutex>
#include "dds/dds.h"
#include "dal/ret_type.h"
#include "dal/guid.h"
#include "dal/domain_participant.h"
#include "dal/participant_monitor.h"
#include "dal_cyclonedds/converter/GuidConverter.hpp"

class ParticipantMonitor
{
public:
    struct callback_info_s {
        dal_participant_monitor_callback callback_ = nullptr;
        void *data_ = nullptr;
        dds_time_t reg_time_ = 0;
    };

private:
    std::vector<callback_info_s*> callback_info_list_;

public:
    ParticipantMonitor() = default;
    ParticipantMonitor(const ParticipantMonitor &) = delete;
    ParticipantMonitor(ParticipantMonitor &&) = delete;
    ParticipantMonitor& operator=(const ParticipantMonitor &) = delete;
    ParticipantMonitor& operator=(ParticipantMonitor &&) = delete;
    ~ParticipantMonitor();

public:
    static ParticipantMonitor& GetInstance();
    void SetMonitor(dds_entity_t monitor_participant,
                    dal_participant_monitor_callback callback, void *data);
    std::mutex mutex_;

private:
    static void ProcessCallback(dds_entity_t reader, void *arg);
};

struct participant_born_info_s {
    uint8_t monitor_flag_ = 0;
    dds_time_t born_time_ = 0;
};

#endif  // _DAL_CYCLONE_PARTICIPANT_MONITOR_HPP_